import React, { useRef, useState, useEffect } from 'react';
import { connect } from 'umi';
import { Dropdown, Space, Button } from 'antd';
import { RightSquareOutlined } from '@ant-design/icons';
import TableDataBlock from '@/components/TableDataBlock';
import PopImgShow from '@/components/PopImgShow';
import Indentation from '@/components/Indentation';
import FormSet from './components/FormSet';
const AnsweringSchedule = (props) => {
    const { userList, loading, dispatch } = props;
    const [visible, setVisible] = useState(false);
    const childRef = useRef();

    const btnExtra = [
        {
            text: '新增',
            onClick: () => {
                setVisible({
                    show: true
                })
            }
        }
    ]
    useEffect(() => {
        fetchData()
    }, [])
    const [list, setList] = useState([])
    const fetchData = () => {
        dispatch({
            type: 'answering/fetchListCampus',
            callback: (e) => {
                setList(e)
            }
        })
    }
    const getColumns = [
        {
            title: '校区名称',
            dataIndex: 'campusName',
        },
        {
            title: '地区',
            dataIndex: 'provinceName',
            render: (e, record) => {
                const {
                    provinceName,
                    cityName,
                    districtName
                } = record
                return provinceName + cityName + districtName
            }
        },
        {
            title: '地址',
            dataIndex: 'address',
            render: (e) => {
                return <Indentation str={e}></Indentation>
            }
        },
        {
            title: '备注',
            dataIndex: 'remark',
            render: (e) => {
                return <Indentation str={e}></Indentation>
            }
        },
        {
            title: '联系方式',
            dataIndex: 'phone',
        },
        {
            type: 'handle',
            width: 200,
            dataIndex: 'id',
            render: (val, record) => [
                {
                    auth: true,
                    title: '编辑',
                    type: 'edit',
                    click: () => {
                        const { provinceCode, cityCode, districtCode } = record
                        setVisible({
                            show: true,
                            detail: {
                                ...record,
                                city: [provinceCode, cityCode, districtCode]
                            }
                        })
                    },
                },
                {
                    auth: true,
                    title: '删除',
                    click: () => {
                        dispatch({
                            type: 'answering/fakeRemoveCampus',
                            payload: {
                                id: val
                            },
                            callback: () => {
                                fetchData()
                            }
                        })
                    },
                },
            ],
        },
    ];
    return (
        <>
            <TableDataBlock
                btnExtra={btnExtra}
                cRef={childRef}
                loading={loading}
                columns={getColumns}
                rowKey={(record) => `${record.id}`}
                pagination={false}
                list={list}
            ></TableDataBlock>
            <FormSet handleCallback={fetchData} visible={visible} onClose={() => {
                setVisible(false)
            }}></FormSet>
        </>
    );
};
export default connect(({ loading, produce }) => ({
    loading: loading.models.produce,
    ...produce,
}))(AnsweringSchedule);
